import { createRouter, createWebHistory } from 'vue-router';
import { CHILD_PREFIX } from '@/micro/config.js'
 
// const routes = [
//   {
//     path: '/',
//     name: 'Home',
//     component: () => import('@/views/Home.vue'),
//   },
//   {
//     path: '/about',
//     name: 'About',
//     component: () => import('@/views/About.vue'),
//   },
//   {
//   	path: `/${CHILD_PREFIX}/first-child`,
//   	name: 'FirstChild',
//   	children: [{
//   		path: 'home',
//   		name: 'FirstHome'
//   	}, {
//   		path: 'about',
//   		name: 'FirstAbout'
//   	}]
//   }, {
//   	path: `/${CHILD_PREFIX}/second-child`,
//   	name: 'SecondChild',
//   	children: [{
//   		path: 'home',
//   		name: 'SecondHome'
//   	}, {
//   		path: 'about',
//   		name: 'SecondAbout'
//   	}]
//   }
// ];
 const routes = [
    {
       path: '/',
       name: 'Home',
       component: () => import('@/views/Home.vue'),
    },
    {
       path: '/about',
       name: 'About',
       component: () => import('@/views/About.vue'),
    },
	{
		path: '/:catchAll(.*)',
		component: () => import('@/views/error.vue'),
	},
   // 微前端路由配置
   {
     path: '/child-app/:page*', // 捕获所有子应用路由
     name: 'child-app',
     component: () => import('@/views/microApp.vue'),
     meta: { requiresAuth: true } // 路由元信息
   },
   {
     path: '/child-app-about',
     name: 'child-app-about',
     component: () => import('@/views/microApp.vue'),
     props: { page: 'about' } // 传递特定页面参数
   }
 ]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL), // 使用 HTML5 历史模式
  routes, // `routes: routes` 的缩写
});
router.beforeEach((to, from) => {
   if (to.name === 'child-app' && !localStorage.getItem('token')) {
     return { name: 'login' }
   }
})
export default router;